package com.ruoyi.project.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.project.domain.MTStudent;
import com.ruoyi.project.service.IMTStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 学生信息Controller
 * 
 * @author ruoyi
 * @date 2024-07-28
 */
@RestController
@RequestMapping("/project/student")
public class MTStudentController extends BaseController
{
    @Autowired
    private IMTStudentService mTStudentService;

    /**
     * 查询学生信息列表
     */
    @PreAuthorize("@ss.hasPermi('project:student:list')")
    @GetMapping("/list")
    public TableDataInfo list(MTStudent mTStudent)
    {
        startPage();
        // 1.测试使用mybatis的where
        testMybatisWhere();


        List<MTStudent> list = mTStudentService.selectMTStudentList(mTStudent);
        return getDataTable(list);
    }

    private void testMybatisWhere() {
        List<MTStudent> studentList = new ArrayList<>();
        studentList.add(new MTStudent("ST0728001","fafa","0"));
        studentList.add(new MTStudent("ST0728002","小明","0"));
        studentList.add(new MTStudent("ST0728003","小红","1"));
        List<MTStudent> studentList1 = mTStudentService.selectMTStudentListByStus(studentList);
        studentList1.forEach(System.out::println);
    }

    /**
     * 导出学生信息列表
     */
    @PreAuthorize("@ss.hasPermi('project:student:export')")
    @Log(title = "学生信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MTStudent mTStudent)
    {
        List<MTStudent> list = mTStudentService.selectMTStudentList(mTStudent);
        ExcelUtil<MTStudent> util = new ExcelUtil<MTStudent>(MTStudent.class);
        util.exportExcel(response, list, "学生信息数据");
    }

    /**
     * 获取学生信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:student:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(mTStudentService.selectMTStudentById(id));
    }

    /**
     * 新增学生信息
     */
    @PreAuthorize("@ss.hasPermi('project:student:add')")
    @Log(title = "学生信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MTStudent mTStudent)
    {
        return toAjax(mTStudentService.insertMTStudent(mTStudent));
    }

    /**
     * 修改学生信息
     */
    @PreAuthorize("@ss.hasPermi('project:student:edit')")
    @Log(title = "学生信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MTStudent mTStudent)
    {
        return toAjax(mTStudentService.updateMTStudent(mTStudent));
    }

    /**
     * 删除学生信息
     */
    @PreAuthorize("@ss.hasPermi('project:student:remove')")
    @Log(title = "学生信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(mTStudentService.deleteMTStudentByIds(ids));
    }
}
